Completed
Push — master ( 430c18...52d1c6 )
by
unknown
54s
created

operations.js ➔ ... ➔ it(ꞌcmsOperations.create()ꞌ)   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
dl 0
loc 12
rs 9.4285
nop 1
1
var chai = require('chai');
2
var path = require('path');
3
4
var config = require('../src/cli').config
5
config.set({root: path.join(__dirname,'fixtures')})
6
7
var cmsOperations = require('../src/cli').cmsOperations
8
var Manager = require('../src/cli').Manager;
9
var fse = require('fs-extra');
10
11
describe('cmsOperations', function() {
12
  before( function(done) {
13
    Manager.instance.init()
14
      .then(function () {
15
        Manager.instance._whereKeys = ['title', 'priority', 'abe_meta', 'articles']
16
        Manager.instance.updateList()
17
18
        this.fixture = {
19
          jsonArticle: fse.readJsonSync(path.join(__dirname, '/fixtures/files/article-2.json')),
20
          jsonHomepage: fse.readJsonSync(path.join(__dirname, '/fixtures/data/homepage-1.json'))
21
        }
22
        done()
23
        
24
      }.bind(this))
25
  });
26
27
  it('cmsOperations.create()', function(done) {
28
    cmsOperations.create('article', '', 'article-2.html', {query: ''}, JSON.parse(JSON.stringify(this.fixture.jsonArticle)), false)
29
      .then(function(resSave) {
30
        var json = path.join(config.root, config.data.url, resSave.abe_meta.latest.abeUrl.replace('.html', '.json'))
31
        var stat = fse.statSync(json)
32
        if (stat) {
33
          chai.expect(stat).to.not.be.undefined;
0 ignored issues
show
introduced by
The result of the property access to chai.expect(stat).to.not.be.undefined is not used.
Loading history...
34
        }
35
        fse.removeSync(json)
36
        done()
37
      }.bind(this));
0 ignored issues
show
unused-code introduced by
The call to bind does not seem necessary since the function does not use this. Consider calling it directly.
Loading history...
38
  });
39
40
  /**
41
   * cmsOperations.post.publish
42
   * 
43
   */
44
  it('cmsOperations.post.publish()', function(done) {
45
    cmsOperations.post.publish('article-2.html', JSON.parse(JSON.stringify(this.fixture.jsonArticle)))
46
      .then(function(resSave) {
47
        var json = path.join(config.root, config.data.url, resSave.json.abe_meta.latest.abeUrl.replace('.html', '.json'))
48
        var stat = fse.statSync(json)
49
        if (stat) {
50
          chai.expect(stat).to.not.be.undefined;
0 ignored issues
show
introduced by
The result of the property access to chai.expect(stat).to.not.be.undefined is not used.
Loading history...
51
        }
52
        fse.removeSync(json)
53
54
        var html = path.join(config.root, config.publish.url, resSave.json.abe_meta.link)
55
        var stat = fse.statSync(html)
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable stat already seems to be declared on line 48. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
56
        if (stat) {
57
          chai.expect(stat).to.not.be.undefined;
0 ignored issues
show
introduced by
The result of the property access to chai.expect(stat).to.not.be.undefined is not used.
Loading history...
58
        }
59
        fse.removeSync(html)
60
        done()
61
      }.bind(this));
0 ignored issues
show
unused-code introduced by
The call to bind does not seem necessary since the function does not use this. Consider calling it directly.
Loading history...
62
  });
63
64
  /**
65
   * cmsOperations.post.unpublish
66
   * 
67
   */
68
  it('cmsOperations.post.unpublish()', function(done) {
69
    cmsOperations.post.publish('article-2.html', JSON.parse(JSON.stringify(this.fixture.jsonArticle)))
70
    .then(function(resSave) {
71
      var json = path.join(config.root, config.data.url, resSave.json.abe_meta.latest.abeUrl.replace('.html', '.json'))
72
      var html = path.join(config.root, config.publish.url, resSave.json.abe_meta.link)
73
      cmsOperations.post.unpublish('article-2.html')
74
      .then(function(resSave2) {
75
        var stat
76
        try {
77
          var stat = fse.statSync(json)
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable stat already seems to be declared on line 75. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
78
        }catch(e) {
79
          chai.expect(stat).to.be.undefined;
0 ignored issues
show
introduced by
The result of the property access to chai.expect(stat).to.be.undefined is not used.
Loading history...
80
        }
81
        try {
82
          var stat = fse.statSync(html)
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable stat already seems to be declared on line 75. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
83
        }catch(e) {
84
          chai.expect(stat).to.be.undefined;
0 ignored issues
show
introduced by
The result of the property access to chai.expect(stat).to.be.undefined is not used.
Loading history...
85
        }
86
        json = path.join(config.root, config.data.url, resSave2.json.abe_meta.latest.abeUrl.replace('.html', '.json'))
87
        var stat = fse.statSync(json)
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable stat already seems to be declared on line 75. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
88
        if (stat) {
89
          chai.expect(stat).to.not.be.undefined;
0 ignored issues
show
introduced by
The result of the property access to chai.expect(stat).to.not.be.undefined is not used.
Loading history...
90
        }
91
        fse.removeSync(json)
92
        done()
93
      }.bind(this));
0 ignored issues
show
unused-code introduced by
The call to bind does not seem necessary since the function does not use this. Consider calling it directly.
Loading history...
94
    }.bind(this));
95
  });
96
97
  /**
98
   * cmsOperations.post.draft
99
   * 
100
   */
101
  it('cmsOperations.post.draft()', function(done) {
102
    cmsOperations.post.draft('article-2.html', JSON.parse(JSON.stringify(this.fixture.jsonArticle)))
103
      .then(function(resSave) {
104
        var json = path.join(config.root, config.data.url, resSave.json.abe_meta.latest.abeUrl.replace('.html', '.json'))
105
        var stat = fse.statSync(json)
106
        if (stat) {
107
          chai.expect(stat).to.not.be.undefined;
0 ignored issues
show
introduced by
The result of the property access to chai.expect(stat).to.not.be.undefined is not used.
Loading history...
108
        }
109
        fse.removeSync(json)
110
        done()
111
      }.bind(this));
0 ignored issues
show
unused-code introduced by
The call to bind does not seem necessary since the function does not use this. Consider calling it directly.
Loading history...
112
  });
113
114
  /**
115
   * cmsOperations.post.reject
116
   * 
117
   */
118
  it('cmsOperations.post.reject()', function(done) {
119
    cmsOperations.post.reject('article-2.html', JSON.parse(JSON.stringify(this.fixture.jsonArticle)))
120
      .then(function(resSave) {
121
        var json = path.join(config.root, config.data.url, resSave.json.abe_meta.latest.abeUrl.replace('.html', '.json'))
122
        var stat = fse.statSync(json)
123
        if (stat) {
124
          chai.expect(stat).to.not.be.undefined;
0 ignored issues
show
introduced by
The result of the property access to chai.expect(stat).to.not.be.undefined is not used.
Loading history...
125
        }
126
        fse.removeSync(json)
127
        done()
128
      }.bind(this));
0 ignored issues
show
unused-code introduced by
The call to bind does not seem necessary since the function does not use this. Consider calling it directly.
Loading history...
129
  });
130
131
  it('cmsOperations.duplicate()', function(done) {
132
    cmsOperations.duplicate('article-1.html', 'article', '', 'article-2.html', {}, false)
133
    .then(function(resSave) {
134
      var json = path.join(config.root, config.data.url, resSave.abe_meta.latest.abeUrl.replace('.html', '.json'))
135
      var stat = fse.statSync(json)
136
      if (stat) {
137
        chai.expect(stat).to.not.be.undefined;
0 ignored issues
show
introduced by
The result of the property access to chai.expect(stat).to.not.be.undefined is not used.
Loading history...
138
      }
139
      fse.removeSync(json)
140
      done()
141
    }.bind(this))
0 ignored issues
show
unused-code introduced by
The call to bind does not seem necessary since the function does not use this. Consider calling it directly.
Loading history...
142
  });
143
144
  it('cmsOperations.duplicate() update', function(done) {
145
    cmsOperations.duplicate('article-1.html', 'article', '', 'article-1.html', {}, true)
146
    .then(function(resSave) {
147
      var json = path.join(config.root, config.data.url, resSave.abe_meta.latest.abeUrl.replace('.html', '.json'))
148
      var stat = fse.statSync(json)
149
      if (stat) {
150
        chai.expect(stat).to.not.be.undefined;
0 ignored issues
show
introduced by
The result of the property access to chai.expect(stat).to.not.be.undefined is not used.
Loading history...
151
      }
152
      fse.removeSync(json)
153
      done()
154
    }.bind(this))
0 ignored issues
show
unused-code introduced by
The call to bind does not seem necessary since the function does not use this. Consider calling it directly.
Loading history...
155
  });
156
});
157